<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>待审核商家</legend>
            <div class="demoTable" style="float:right">
                <label class="layui-form-label">搜索条件</label>
                <div class="layui-input-inline">
                    <select name="condition" id="select"
                            style="height: 30px;background-color: #bfdce5;border-radius: 5px">
                        <option value="">请选择</option>
                        <option value="1">编号</option>
                        <option value="2">店名</option>
                        <option value="3">注册人</option>
                        <option value="4">类型</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <input class="layui-input" style="border-radius: 15px;" name="num" id="demoReload"
                           autocomplete="off">
                </div>
                <button class="layui-btn" style="border-radius: 15px;background-color: rgb(255,255,255)"
                        data-type="reload">
                    <i class="layui-icon layui-icon-search" style="font-size: 30px; color: #429adc;"></i></button>
            </div>
        </fieldset>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal  layui-btn-radius" style="background-color: #d1e3cc"
                        lay-event="writeExcel">导出Excel
                </button>
            </div>
        </script>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal  layui-btn-radius data-count-edit" style="background-color: #8bfaa1"
               lay-event="yes"><i class="layui-icon layui-icon-ok" style="font-size: 10px;"></i>通过</a>
            <a class="layui-btn layui-btn-normal  layui-btn-radius data-count-delete" style="background-color: #d7445a"
               lay-event="no"><i class="layui-icon layui-icon-close"></i>驳回</a>
        </script>


    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        table.render({
            //cellHeight: 300,
            skin: 'nob',// 无边框风格
            // size:'lg',// 大尺寸
            cellMinWidth: 80,
            elem: '#currentTableId',
            url: 'store/findByPage',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'num', width: 80, title: '编号', sort: true, align: "center"},
                {field: 'urls', title: '图标', templet: '#img', align: "center"},
                {field: 'store', width: 80, title: '店名', align: "center"},
                {field: 'name', width: 80, title: '注册人', align: "center"},
                {
                    field: 'time',
                    title: '注册时间',
                    templet: "<div> {{layui.util.toDateString(d.time,'yyyy-MM-dd') }} </div>",
                    align: 'center'
                }, {field: 'money', title: '注册资金(元)', align: "center"},
                {field: 'address', title: '注册地址', align: "center"},
                {field: 'type', title: '店铺类型', align: "center"},
                {
                    field: 'sta', width: 80, title: '状态', align: "center", templet: function (d) {
                        if (d.sta == 1) {
                            res = "待审核"
                        } else if (d.sta == 2) {
                            res = "待缴纳保证金"
                        } else if (d.sta == 3) {
                            res = "营业中"
                        } else if (d.sta == 4) {
                            res = "整改中"
                        } else if (d.sta == 5) {
                            res = "已下架/未上架"
                        }
                        return res;
                    }
                },
                {title: '操作', minWidth: 220, toolbar: '#currentTableBar', align: "center"}
            ]],
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
                limits: [5, 10, 15, 20, 25],
                limit: 5,
                page: true,
                skin: 'line',
                groups: 1 //只显示 1 个连续页码
                , first: "首页"
                , last: "尾页"
            }
        });
        // 监听搜索操作
        var $ = layui.$, active = {
            reload: function () {
                var num = $('#demoReload');
                var condition = $('#select')
                //console.log(username.val());
                //执行重载
                table.reload('currentTableId', {
                    page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                        layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'], //自定义分页布局
                        limits: [5, 10, 15, 20, 25],
                        limit: 5,
                        page: true,
                        skin: 'line',
                        groups: 1 //只显示 1 个连续页码
                        , first: "首页"
                        , last: "尾页"
                    }
                    , where: {
                        v: num.val(),
                        c: condition.val()
                    }
                }, 'data');
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

//头工具栏事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'writeExcel':
                    //location对象的href属性表示跳转到指定路径
                    location.href = "/store/wirteExcel"

                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            }
            ;
        });

        //监听行工具事件
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            //console.log(data);;
            if (obj.event === 'yes') {
                //修改操作
                var Id = data.num;
                $.get("/store/yes", {num: Id},
                    function (data) {
                        if ("success" == data) {
                            table.reload("currentTableId", {});//重新加载当前表格
                        }
                    });
            } else if (obj.event === 'no') {
                //修改操作
                var Id = data.num;
                $.get("/store/no", {num: Id},
                    function (data) {
                        if ("success" == data) {
                            table.reload("currentTableId", {});//重新加载当前表格
                        }
                    });
            }
        });


    });
</script>

<script type="text/html" id="img">
    <div><img src="{{d.urls}}" style="object-fit: scale-down;border-radius: 50px"></div>
</script>
</body>
<style>
    .layui-table-cell {
        height: auto;
        /* width: auto;
         min-width: 100px;*/
        line-height: 30px;
    }
</style>
</html>